package com.bizihang.security.browser.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author 毕子航 951755883@qq.com
 * @date 2018/08/15
 */
@Slf4j
@Component
public class BrowserUserDetailService implements UserDetailsService {

	@Autowired
	PasswordEncoder passwordEncoder;


	@Override
	public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
		log.info("{}尝试登陆", s);

		String encode = passwordEncoder.encode("123456");
		//根据用户名查找用户信息
		return new User(s, encode, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
	}
}
